var wf = {
	disagree : function(fid,direction,form,methodName,prefunc){
	
		let exec = true;
		if(prefunc){
			exec = window[prefunc]();
		}
		if(!exec){
			return false;
		}
		methodName = methodName || "";
		
		form.on('submit(disagreeform)', function(data){
		  axios.post('wfNodeInst/audit',{wfNodeInstId:fid ,opinion:$('#opinion').val(),direction:direction, approve:"disagree",method:methodName}).then(res=>{
				if(res.data.code==1){
					layer.msg(res.data.msg);
				}else{
					let win = getTabWin();
					win.loadGrid("main-table");
					layer.msg("提交成功");
					var index = top.layer.getFrameIndex(window.name); 
					top.layer.close(index); 
				}
			})
			return false; 
	    });
	},
	agree : function(fid,direction,form,methodName,prefunc){
		form.on('submit(agreeform)', function(data){
			let exec = true;
			if(prefunc){
				exec = prefunc();
			}
			if(!exec){
				return false;
			}
			methodName = methodName || "";
			
			if(typeof(methodName)==="function"){
				methodName = methodName();
			}
			axios.post('wfNodeInst/audit',{wfNodeInstId:fid ,direction: direction,opinion:$('#opinion').val(), approve:"agree",method: methodName}).then(res=>{
				if(res.data.code==1){
					layer.msg(res.data.msg);
				}else{
					let win = getTabWin();
					win.loadGrid("main-table");
					layer.msg("提交成功");
					var index = top.layer.getFrameIndex(window.name); 
					top.layer.close(index); 
				}
			})
			return false; 
	    });
	},
	showOpinion: function(fid,form,table){
		table.render({
		  elem: '#opinion-table'
		  ,url: 'wfComment/getList' 
		  ,where:{wfNodeInstId: fid}
	  	  ,cols: [[
			  {field: 'createUserName', title: '审批人',width:120}
			  ,{field: 'nodeName', title: '审批步骤',width:180}
			  ,{field: 'approveTxt', title: '审批态度',width:100}
			  ,{field: 'createTime', title: '审批时间',width:180}
			  ,{field: 'content', title: '意见内容'}
		  ]]
		  ,height: 400
		  ,text: '对不起，加载出现异常！'
		  ,done:function(){
			  enableRowClick(table,form,'opinion-table',"opinion-table");
		  }
	  });
	},showAttachment: function(fid,form,table){
		table.render({
		  elem: '#attachment-table'
		  ,url: 'attachment/getPageList' 
		  ,where:{fid:fid}
	  	  ,cols: [[
	  		  {type: 'checkbox'}
	  		  ,{field: 'id', width: 150, title: 'ID',hide:true}
			  ,{field: 'name', title: '附件名称',width:300}
			  ,{field: 'sizeDesc', title: '文件大小',width:150}
			  ,{field: 'createUserName', title: '上传人',width:190}
			  ,{field: 'createTime', title: '上传时间',width:180}
			  ,{field: 'descs', title: '备注说明'}
		  ]]
		  ,height: 200
		  ,text: '对不起，加载出现异常！'
		  ,done:function(){
			  enableRowClick(table,form,'attachment-table',"attachment-table");
		  }
	  });
	},addAttachment: function addAttachment(){
	       layer.open({
	            type: 2,
	            title:'上传附件',
	            area:['940px','400px'],
	            content: 'rooter?url=equipment/purchase/add-attachment',
	            btn:['上传','关闭'],
	            yes:function(index,layero){
	            	var iframeWin = window[layero.find('iframe')[0]['name']]; 
	                $(iframeWin.document).find("#uploadBtn").click();
	                
	                return false
	            }
	      });    
	 },delAttachment: function (table){
 	      var checkStatus = table.checkStatus('attachment-table')
 	      ,checkData = checkStatus.data; 
 	      var ids = [];
 		  for(let i=0;i<checkData.length;i++){
 			  ids[i] = checkData[i].id;
 		  }
 	      if(checkData.length === 0){
 	          return layer.msg('请选择要删除的附件');
 	      }
 	      layer.confirm('确定删除吗？', function(index) {
 	    	  $.ajax({
 	    		  url:"attachment/delete",
 	    		  type:'POST',
 	    		  dataType:'json',
 	    		  data:{ids: ids},
 	    		  success:function(ret){
 	    			  table.reload('attachment-table');
 	    	          layer.msg('删除成功');
 	    		  }
 	      	  })
 	       })
 	 }


}
